package com.dfbz.service.impl;

import com.dfbz.dao.UserDao;
import com.dfbz.model.User;
import com.dfbz.service.UserService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserServiceImpl implements UserService {

    private UserDao userDao=new UserDao();
    @Override
    public User findByName(String username) {
        List<User> userList=userDao.findByCol("username",username);
        if (userList.isEmpty()){
            return null;
        }else {
            return userList.get(0);
        }
    }
    @Override
    public User findByEmail(String email) {
        List<User> userList=userDao.findByCol("email",email);
        if (userList.isEmpty()){
            return null;
        }else {
            return userList.get(0);
        }
    }
    @Override
    public boolean checkByEmailorName(String email, String username) {
        Map<String,Object> map= new HashMap<>();
        map.put("username",username);
        map.put("email",email);
        List<User> userList=userDao.findByCols("or",map);
        return userList.isEmpty();
    }

    @Override
    public boolean addUser(User user) {
        return true;
    }
}
